package com.mark.controller;


import com.alibaba.fastjson.JSON;
import com.mark.entity.school.MyClaStuTable;
import com.mark.entity.school.UTeacher;
import com.mark.entity.school.UTeacherGroup;
import com.mark.service.UTeacherGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * (UTeacherGroup)表控制层
 *
 * @author Deng PengFei
 * @since 2021-10-27 11:18:26
 */
@CrossOrigin
@RestController
@RequestMapping("teaGroup")
public class UTeacherGroupController {

    @Autowired
    private UTeacherGroupService uTeacherGroupService;


    /**
     * 获取教师分组列表
     *
     * @return 对象列表
     */
    @GetMapping("getTeaGroupList")
    public List<UTeacherGroup> getTeaGroupList() {
        return this.uTeacherGroupService.getTeaGroupList();
    }


    /**
     * 增加一个教师分组
     *
     * @return 1001 成功， 1002 分组已经存在 . 1003 失败
     */
    @PostMapping("addTeaGro")
    public Integer addTeaGro(@RequestBody Map<String, Object> data) {
        List<UTeacher> teachers = JSON.parseArray(JSON.toJSONString(data.get("members")), UTeacher.class);
        UTeacherGroup uTeacherGroup = new UTeacherGroup();
        uTeacherGroup.setGroNm(String.valueOf(data.get("groNm")));
        uTeacherGroup.setGroDesc(String.valueOf(data.get("groDesc")));
        return this.uTeacherGroupService.addTeaGro(uTeacherGroup, teachers);
    }


}